package cn.scxy.bookcity.controller;

import cn.scxy.bookcity.pojo.dto.CollectionDTO;
import cn.scxy.bookcity.pojo.dto.UserLoginDTO;
import cn.scxy.bookcity.pojo.vo.CollectionListItemVO;
import cn.scxy.bookcity.service.ICollectionService;
import cn.scxy.bookcity.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/collection")
@Api(tags = "收藏模块")
@Slf4j
public class CollectionController {

    @Autowired
    ICollectionService collectionService;

    @ApiOperation("查询收藏信息")
    @ApiOperationSupport(order =401)
    @GetMapping("/list")
    public JsonResult<List<CollectionListItemVO>> list(HttpSession session){
        log.debug("开始处理收藏信息");
        UserLoginDTO userLoginDTO= (UserLoginDTO) session.getAttribute("user");
        Integer id = userLoginDTO.getId();
        Long uId = Long.valueOf(id);
        List<CollectionListItemVO> list = collectionService.list(uId);
        return JsonResult.ok(list);
    }


    @PostMapping("/addNew")
    @ApiOperation("添加收藏")
    @ApiOperationSupport(order =301)
    public JsonResult<Void> addNew(CollectionDTO collectionDTO){
        collectionService.addNew(collectionDTO);
        return JsonResult.ok();
    }

}
